package com.wcr.school.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wcr.school.mapper.AdminMapper;
import com.wcr.school.mapper.GradeMapper;
import com.wcr.school.pojo.Admin;
import com.wcr.school.pojo.Grade;
import com.wcr.school.service.AdminService;
import com.wcr.school.service.GradeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

@Service("implGradeService")
@Transactional
public class ImplGradeService  extends ServiceImpl<GradeMapper, Grade> implements GradeService {
    @Override
    public IPage<Grade> getGradeByOption(Page<Grade> page, String gradeName) {
        QueryWrapper<Grade> queryWrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(gradeName))
        queryWrapper.like("name",gradeName);
        queryWrapper.orderByAsc("id");
        Page page1 = baseMapper.selectPage(page,queryWrapper);
        return page1;
    }

    @Override
    public void deleteGrade(List<Integer> list) {
        QueryWrapper<Grade> queryWrapper = new QueryWrapper<>();
        for (int i=0;i<list.size();i++) {
            queryWrapper.eq("id", list.get(i));
            baseMapper.delete(queryWrapper);
        }

    }

    @Override
    public List<Grade> getAllGradeName() {

        return baseMapper.selectList(null);
    }


}
